<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('薪资信息(离职)')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: bootstrap-editable-css"/>

</head>
<body class="gray-bg">
<div class="modal inmodal fade" id="myModal1" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span>
                </button>
                <h4 class="modal-title">选择薪资套类型</h4>
            </div>
            <div class="modal-body">
                <p>
                    <select id="pgid" name='pgid' class="form-control">
                    </select>
                </p>
            </div>
            <div class="modal-footer">
                <button type="button" id="missmodal1" class="btn btn-white" data-dismiss="modal">关闭</button>
                <button type="button" onclick="getPgid()" class="btn btn-primary">确认</button>
            </div>
        </div>
    </div>
</div>
<button type="button" id="modal1" class="btn btn-primary" data-toggle="modal"
        data-target="#myModal1">选择薪资套
</button>


<div class="modal inmodal fade" id="myModal2" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span>
                </button>
                <h4 class="modal-title">修改止薪日期</h4>
            </div>
            <div class="modal-body">
                <p>
                    最新止薪时间:
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    <input type="text" id="EDdate" class="form-control laydate-demo-2" placeholder="yyyy-MM-dd">
                </div>
                </p>
            </div>
            <div class="modal-footer">
                <button type="button" id="missmodal2" class="btn btn-white" data-dismiss="modal">关闭</button>
                <button type="button" onclick="updateProcedure()" class="btn btn-primary">确认</button>
            </div>
        </div>
    </div>
</div>
<button type="button" id="modal2" class="btn btn-primary" data-toggle="modal"
        data-target="#myModal2">选择薪资套
</button>


<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="user-form">
                    <div class="select-list">
                        <ul>
                            <li>
                                工号：<input type="text" name="badge"/>
                            </li>
                            <li>
                                姓名：<input type="text" name="name"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-primary" onclick="updatePayOffDate()">
                    <i class="fa fa-edit"></i> 修改止薪日期
                </a>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: datetimepicker-js"/>


<script th:inline="javascript">
    var prefix = ctx + "salaryDateChange/salaryDateChange";
    var pgid;
    var headField = [];
    $(function () {
        var panehHidden = false;
        if ($(this).width() < 800) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 350});

        $(".datetimepicker-demo-2").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        layui.use('laydate', function () {
            var laydate = layui.laydate;
            laydate.render({
                elem: '.laydate-demo-2',
                type: 'date'
            });
        });

        $("#modal1").attr("style", "display:none;");
        $("#modal2").attr("style", "display:none;");

        getSkypayGroups();
        //queryData();
    });


    /**
     * 获取薪资套列表
     */
    function getSkypayGroups() {
        var html = "";
        $.ajax({
            async: false,
            url: ctx + "salaryCalculation/getSkypayGroups",
            data: {},
            type: "post",
            dataType: "json",
            success: function (data) {
                $("#pgid").empty();
                var arry = data;
                for (var i = 0; i < arry.length; i++) {
                    html += "<option value='"
                        + arry[i].id
                        + "'>"
                        + arry[i].title
                        + "</option>";
                }
                $("#pgid").append(html);
                $("#modal1").click();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }

    function getPgid() {
        pgid = $("#pgid").val();
        $("#missmodal1").click();
        getData();
    }

    function getData() {
        var columns = [];
        var other;
        var checkbox = {checkbox: true}
        var badge = {field: 'badge', title: '工号'};
        var name = {field: 'name', title: '姓名'};
        var compName = {field: 'compName', title: '公司'};
        var depName = {field: 'depName', title: '部门名称'};
        var jobName = {field: 'jobName', title: '岗位'};
        var empStatusName = {field: 'empStatusName', title: '员工状态'};
        var jobStatusName = {field: 'jobStatusName', title: '在岗状态'};
        var idTypeName = {field: 'idTypeName', title: '证件类型'};
        var idCard = {field: 'idCard', title: '证件编号'};
        var empStartDate = {field: 'empStartDate', title: '入职日期'};
        var empEndDate = {field: 'empEndDate', title: '离职日期'};
        var pzidName = {field: 'pzidName', title: '薪资区域'};
        var costcenterName = {field: 'costcenterName', title: '成本中心'};
        var startDate = {field: 'startDate', title: '起薪日期'};
        var endDate = {field: 'endDate', title: '止薪日期'};
        var paystatusName = {field: 'paystatusName', title: '薪资状态'};
        var payHolding = {field: 'payHolding', title: '薪资挂起'};

        columns.push(checkbox, badge, name, compName, depName, jobName, empStatusName, jobStatusName, idTypeName);
        columns.push(idCard, empStartDate, empEndDate, pzidName, costcenterName, startDate, endDate, paystatusName, payHolding);

        $.ajax({
            async: false,
            url: ctx + "salaryAdmin/findProByPgid",
            data: {"pgid": pgid},
            type: "post",
            dataType: "json",
            success: function (data) {
                for (var i = 0; i < data.length; i++) {
                    other = {
                        field: data[i], title: data[i]
                    }
                    columns.push(other);
                }
                var options = {
                    code: "id",
                    uniqueId: "id",
                    pagination: false,
                    url: prefix + "/list?pgid=" + pgid,
                    height: $(window).height() - 120,
                    modalName: "薪资信息(离职)",
                    columns: columns
                };
                $.table.init(options);
            },
        });
    }

    function updatePayOffDate() {
        $("#modal2").click();
    }

    function updateProcedure() {
        var row = $("#bootstrap-table").bootstrapTable('getSelections');
        if (row.length == 0) {
            $.modal.alertWarning("请选择数据!");
            return;
        }
        var allPeid = "";
        for (var i = 0; i < row.length; i++) {
            if (i == row.length - 1) {
                allPeid += row[i].peid
            } else {
                allPeid += row[i].peid + ","
            }
        }
        var EDdate = $("#EDdate").val();

        $.ajax({
            async: false,
            url: prefix + "/updateProcedure",
            data: {"allPeid": allPeid, "EDdate": EDdate},
            type: "post",
            dataType: "json",
            success: function (data) {
                console.log(data);
                if(data.data == null){
                    $.modal.alertWarning(data.message);
                }else{
                    $.modal.alertSuccess(data.data);
                }
                $("#myModal2").click();
                $.table.refresh();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.modal.alertWarning("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }

</script>
</body>
</html>